<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	 .errorText
	 {
	     color:red;
	 }
	</style>
</head>
<body>
	<form id="form1" method="post">
	<input name="id" class="mini-hidden" />
        <div style="padding-left:20px;padding-bottom:15px;">
            <table style="table-layout:fixed;" cellspacing="5" cellpadding="10">
            	<tr>
            		<td style="width:90px;">公司名称：</td>
                    <td style="width:180px;">   
                        <input name="name" errorMode="none" onvalidation="checkValidation" requiredErrorText="公司名称不能为空"  class="mini-textbox" required="true" vtype="maxLength:255" style="width: 300px" emptyText="请输入公司全称"/>
                    </td>
                    <td id="name_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td style="width:100px;">公司简称：</td>
                    <td style="width:180px;">    
                        <input name="abbreviation" errorMode="none" onvalidation="checkValidation" class="mini-textbox"  vtype="maxLength:32" required="false" style="width: 300px" />
                    </td>
                    <td id="abbreviation_error" class="errorText" ></td>
                </tr>
                <tr>
               	                <tr>
                    <td>是否代收费</td>
                    <td>
                        <input id="logistic_genCha_type" name="genCha" errorMode="none" onvalidation="checkValidation" requiredErrorText="请选择是否代收费"  class="mini-combobox" required="true" valueField="keyName" style="width: 300px" textField="keyValue"/>
                    </td>
                     <td id="genCha_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td>是否合作中</td>
                    <td>
                        <input name="cooperation" errorMode="none" onvalidation="checkValidation" requiredErrorText="请选择是否合作中" url="dictionary_wm_key_val_view.do?typeName=LOGISTIC_COO_TYPE" class="mini-combobox" required="true" valueField="keyName" style="width: 300px" textField="keyValue"/>
                    </td>
                     <td id="cooperation_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td style="width:70px;">联系人：</td>
                    <td style="width:180px;">    
                        <input name="conPeo" errorMode="none" onvalidation="checkValidation"  class="mini-textbox"  requiredErrorText="联系人不能为空" required="true"  vtype="maxLength:30" style="width: 300px"/>
                    </td>
                    <td id="conPeo_error" class="errorText" ></td>
                </tr>
                <tr>
                	<td style="width:70px;">联系电话：</td>
                    <td style="width:180px;">
                    	<input name="phone" errorMode="none" onvalidation="onphoneNumValidation"  requiredErrorText="联系电话不能为空" required="true" class="mini-textbox"  vtype="maxLength:20" style="width: 300px"  />
                    </td>
                    <td id="phone_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td style="width:70px;">传真：</td>
                    <td style="width:180px;">    
                        <input name="fax" errorMode="none" onvalidation="checkValidation"  class="mini-textbox" required="false"  vtype="maxLength:20" style="width: 300px" />
                    </td>
                    <td id="fax_error" class="errorText" ></td>
                </tr>
                <tr>
                	<td style="width:70px;">网址：</td>
                	<td style="width:180px;">    
                    	<input name="website" errorMode="none" onvalidation="checkValidation"   class="mini-textbox" required="false" vtype="maxLength:255" style="width: 300px"  />
                	</td>
                	<td id="website_error" class="errorText" ></td>
                </tr>
                <tr>
                    <td >备注：</td>
                    <td colspan="3">    
                        <input name="remark" class="mini-textarea" onvalidation="checkValidation"  vtype="maxLength:255" required="false"  style="width:300px;" />
                    </td>
                    <td id="remark_error" class="errorText" ></td>
                </tr>
            </table>
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
</body>
</html>

<script type="text/javascript">
	mini.parse();
	
	//加载入库类型数据
	var gtype = mini.get(logistic_genCha_type);
	gtype.load('dictionary_wm_key_val_view.do?typeName=LOGISTIC_GENCHA_TYPE');
	
	var form = new mini.Form("form1");
	
	//保存数据
	function SaveData() {
	    var o = form.getData(true); 
	    form.validate();
	    if (form.isValid() == false) return;
	    $.ajax({
	        url: "logistics_save_edit.do",
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误！");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
	}
	

    //标准方法接口定义
    function SetData(data) {
        if (data.action == "edit") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            form.setData(data.row);
            form.setChanged(false);
        }
    }

    function GetData() {
        var o = form.getData();
        return o;
    }
    
    function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onOk(e) {
        SaveData();
    }
    
    function onCancel(e) {
        CloseWindow("cancel");
    }
    
    function onphoneNumValidation(e) {
		var id =e.sender.name + "_error";
		var el = document.getElementById(id);
		checkValidation(e);
        if (e.isValid) {
            if (isEnglishAndNumber(e.value) == false) {
                e.errorText = "电话号码不正确";
                el.innerHTML =e.errorText;
                e.isValid = false;
            }
        }
    }
    
    function isEnglishAndNumber(v) {
        var re = new RegExp("^[0-9]{1,20}$");
        if (re.test(v)) return true;
        return false;
    }
    
    function updateError(e) {
        var id =e.sender.name + "_error";
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML =e.errorText;
        }
    }
    
    function checkValidation(e) {                  
        updateError(e);
    }
</script>